package weaver.interfaces.denou.duss.action;

import com.weaver.general.BaseBean;
import weaver.conn.RecordSet;
import weaver.formmode.setup.ModeRightInfo;
import weaver.general.Util;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.RequestInfo;

/**
 * @Title: ecology-9-demo
 * @Company: 泛微软件
 * @author: weaver.Dusongsong
 * @version: 1.0
 * @CreateDate: 2020-10-23
 * @Description: 咨询项目变更的流程接口
 * @ModifyLog:
 **/
/*
 *@Param:
 *@return:
 *@Author: Dusongsong
 *@Date: 2022/02/23
 */
public class WeaZxxmbgAction extends BaseBean implements Action {

    @Override
    public String execute(RequestInfo requestInfo) {
        RecordSet rs = new RecordSet();
        String requestid = requestInfo.getRequestid();
        String tablename = requestInfo.getRequestManager().getBillTableName();//主表
        writeLog( "----WeaZxxmbgAction-------" + requestid );
        try {
            String sql = "select id,xryap,xxmjl,xxmjlbm,xmmc from " + tablename + " where requestid=?";
            rs.executeQuery( sql, requestid );
            rs.writeLog( sql, requestid );
            if (rs.next()) {
                String xryap = Util.null2String( rs.getString( "xryap" ) );//新人员安排
                String xxmjl = Util.null2String( rs.getString( "xxmjl" ) );//新项目经理
                String xxmjlbm = Util.null2String( rs.getString( "xxmjlbm" ) );//新项目经理部门
                String xmmc = Util.null2String( rs.getString( "xmmc" ) );//项目名称
                if (!"".equals( xryap ) && !"".equals( xxmjl ) && !"".equals( xxmjlbm )) {
                    //付款台账
                    int dataid1 = getDataId( "uf_fktz", xmmc );
                    String sql1 = "update uf_fktz set xmcy=?,xmjl=?,xmjlbm=? where xmmc=?";
                    if (rs.executeUpdate( sql1, xryap, xxmjl, xxmjlbm, xmmc )) {
                        newModeRight( Util.getIntValue( xxmjl ), 41, dataid1 );
                    }
                    //前期测算数据
                    int dataid2 = getDataId( "uf_qqcssjrw", xmmc );
                    String sql2 = "update uf_qqcssjrw set xmcy=?,xmjl=?,xmjlbm=? where xmmc=?";
                    if (rs.executeUpdate( sql2, xryap, xxmjl, xxmjlbm, xmmc )) {
                        newModeRight( Util.getIntValue( xxmjl ), 37, dataid2 );
                    }
                    //招标阶段
                    int dataid3 = getDataId( "uf_zbjd", xmmc );
                    String sql3 = "update uf_zbjd set xmcy=?,xmjl=?,xmjlbm=? where xmmc=?";
                    if (rs.executeUpdate( sql3, xryap, xxmjl, xxmjlbm, xmmc )) {
                        newModeRight( Util.getIntValue( xxmjl ), 40, dataid3 );
                    }
                    //施工合同
                    int dataid4 = getDataId( "uf_sght", xmmc );
                    String sql4 = "update uf_sght set xmcy=?,xmjl=?,xmjlbm=? where xmmc=?";
                    if (rs.executeUpdate( sql4, xryap, xxmjl, xxmjlbm, xmmc )) {
                        newModeRight( Util.getIntValue( xxmjl ), 36, dataid4 );
                    }
                    //预算编制
                    int dataid5 = getDataId( "formtable_main_105", xmmc );
                    String sql5 = "update formtable_main_105 set xmcy=?,xmjl=?,xmjlbm=? where xmmc=?";
                    if (rs.executeUpdate( sql5, xryap, xxmjl, xxmjlbm, xmmc )) {
                        newModeRight( Util.getIntValue( xxmjl ), 58, dataid5 );
                    }
                    //预算审核
                    int dataid6 = getDataId( "formtable_main_108", xmmc );
                    String sql6 = "update formtable_main_108 set xmcy=?,xmjl=?,xmjlbm=? where xmmc=?";
                    if (rs.executeUpdate( sql6, xryap, xxmjl, xxmjlbm, xmmc )) {
                        newModeRight( Util.getIntValue( xxmjl ), 59, dataid6 );
                    }
                    //签证变更台账
                    int dataid7 = getDataId( "uf_qzbgtz", xmmc );
                    String sql7 = "update uf_qzbgtz set xmcy=?,xmjl=?,xmjlbm=? where xmmc=?";
                    if (rs.executeUpdate( sql7, xryap, xxmjl, xxmjlbm, xmmc )) {
                        newModeRight( Util.getIntValue( xxmjl ), 42, dataid7 );
                    }
                    //审计报告登记一览表
                    int dataid8 = getDataId( "uf_sjbgdjylb", xmmc );
                    String sql8 = "update uf_sjbgdjylb set xmcy=?,xmjl=?,xmjlbm=? where xmmc=?";
                    if (rs.executeUpdate( sql8, xryap, xxmjl, xxmjlbm, xmmc )) {
                        newModeRight( Util.getIntValue( xxmjl ), 44, dataid8 );
                    }
                    //项目月报
                    int dataid9 = getDataId( "uf_xmyb", xmmc );
                    String sql9 = "update uf_xmyb set xmcy=?,tbr=?,tbrbm=? where xmmc=?";
                    if (rs.executeUpdate( sql9, xryap, xxmjl, xxmjlbm, xmmc )) {
                        newModeRight( Util.getIntValue( xxmjl ), 50, dataid9 );
                    }
                }
                //业绩统计汇总表
                if (!"".equals( xxmjl ) && !"".equals( xxmjlbm )) {
                    int dataid10 = getDataId( "uf_yjtjhzb", xmmc );
                    String sql10 = "update uf_yjtjhzb set xmcy=?,tbr=?,tbrbm=? where xmmc=?";
                    if (rs.executeUpdate( sql10, xryap, xxmjl, xxmjlbm, xmmc )) {
                        newModeRight( Util.getIntValue( xxmjl ), 45, dataid10 );
                    }

                }
            }


            return Action.SUCCESS;
        } catch (Exception e) {
            e.printStackTrace();
            writeLog( "异常参考:" + e );
            requestInfo.getRequestManager().setMessageid( "111111" );
            requestInfo.getRequestManager().setMessagecontent( "Action接口异常！" );
            return Action.FAILURE_AND_CONTINUE;
        }
    }

    //建模权限重构
    public static void newModeRight(int userid, int formmodeid, int id) {
        ModeRightInfo modeRightInfo = new ModeRightInfo();
        modeRightInfo.setNewRight( true );
        modeRightInfo.editModeDataShare( userid, formmodeid, id );
    }

    //获取建模数据ID
    public static int getDataId(String tablename, String xmmc) {
        RecordSet rs = new RecordSet();
        rs.executeQuery( "select id from " + tablename + " where xmmc=?", xmmc );
        rs.next();
        int id = Util.getIntValue( rs.getString( "id" ), -1 );
        return id;
    }
}
